package com.ex.mzwqz.fragment;

import android.support.v4.view.ViewPager;

import com.ex.mzwqz.R;
import com.ex.mzwqz.adapter.NewsTabAdapter;
import com.ex.mzwqz.widget.viewpagerindicator.TabPageIndicator;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xiaguoqiang on 16/10/19.
 */
public class InformationFragment extends BaseFragment implements ViewPager.OnPageChangeListener {

    private TabPageIndicator mIndicator;
    private ViewPager mViewPager;
    private NewsTabAdapter tabAdapter;
    private List<NewsFragment> fragments = new ArrayList<>();
    private NewsFragment homePageFragment;
    private NewsFragment newsFragment;
    private NewsFragment policyFragment;
    private NewsFragment knowledgeFragment;
    private int position;
    private int size;

    @Override
    protected int setContentViewResId() {
        return R.layout.fragment_information;
    }

    @Override
    protected void initView() {
        newsFragment = new NewsFragment(1);
        policyFragment = new NewsFragment(2);
        knowledgeFragment = new NewsFragment(3);
        homePageFragment = new NewsFragment(0);
        homePageFragment.setTitle("首页");
        newsFragment.setTitle("新闻");
        policyFragment.setTitle("政策");
        knowledgeFragment.setTitle("知识");

        fragments.add(homePageFragment);
        fragments.add(newsFragment);
        fragments.add(policyFragment);
        fragments.add(knowledgeFragment);
        mIndicator = (TabPageIndicator) findViewById(R.id.tabindincator);
        mViewPager = (ViewPager) findViewById(R.id.vp_news);
        tabAdapter = new NewsTabAdapter(getActivity().getSupportFragmentManager(),fragments);
        mViewPager.setAdapter(tabAdapter);
        mViewPager.setOffscreenPageLimit(size);
        mIndicator.setViewPager(mViewPager);
        mIndicator.setCurrentItem(position);
        mViewPager.setOnPageChangeListener(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        mIndicator.setCurrentItem(position);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
